<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>菜鸟教程 React 实例-ajax请求</title>
    <script src="https://cdn.bootcss.com/react/15.4.2/react.min.js"></script>
  <script src="https://cdn.bootcss.com/react/15.4.2/react-dom.min.js"></script>
  <script src="https://cdn.bootcss.com/babel-standalone/6.22.1/babel.min.js"></script>
  <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
  </head>
 <body>
    <div id="example"></div>
    <!-- babel javascript -->
    <script type="text/babel">
    var AjaxTest = React.createClass({
      getInitialState: function() {
        return {
          username:'',
          lastGistUrl:''
        }
      },
      componentDidMount: function() {
        this.serverRequest = $.get(this.props.source,function(result){
          var lastGist = result[0];
          this.setState({
            username:lastGist.owner.login,
            lastGistUrl:lastGist.html_url
          })
        }.bind(this)
        );
      },
      render: function() {
        return (
          <div>
            <p>{this.state.username}用户最新的Gist共享地址：</p>
            <a href={this.state.lastGistUrl}>this.state.lastGistUrl</a>
          </div>
          )
      }
    });
    
    ReactDOM.render(
      <AjaxTest source="https://api.github.com/users/octocat/gists" />,
      document.getElementById('example')
    )
    </script>
  </body>
</html>